package basic.socket.udp.thread;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 * @author bingo
 * @Description
 * @Date 2018/7/18
 */
public class SendThread implements   Runnable {

    private DatagramSocket ds;

    public SendThread(DatagramSocket ds) {
        this.ds = ds;
    }

    @Override
    public void run() {
        DatagramSocket ds = null;
        try {
            ds = new DatagramSocket();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
            byte[] data;
            String line;
            while ((line=bufferedReader.readLine())!=null){
            data = line.getBytes();
            DatagramPacket dp = new DatagramPacket(data,data.length, InetAddress.getByName("127.0.0.1"),8888);
            ds.send(dp);
          }
          ds.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
